import { CoolController, BaseController } from '@cool-midway/core';
import { GoodsPromoMsEntity } from '../../entity/promo_ms';
import { GoodsPromoMsService } from '../../service/promo_ms.service';
import { Body, Inject, Post } from '@midwayjs/core';

/**
 * 促销秒杀管理
 */
@CoolController({
  api: ['page', 'info'],
  entity: GoodsPromoMsEntity,
  service: GoodsPromoMsService,
  pageQueryOp: {
    keyWordLikeFields: ['a.goodsId'],
    fieldEq: ['a.status', 'a.billNo'],
    addOrderBy: {
      createTime: 'desc',
    },
  },
})
export class AdminGoodsPromoMsController extends BaseController {
  @Inject()
  goodsPromoMsService: GoodsPromoMsService;

  @Post('/getByBillNo')
  async getByBillNo(@Body() params: { billNo: string }) {
    return this.ok(await this.goodsPromoMsService.getByBillNo(params.billNo));
  }

  @Post('/getByGoodsId')
  async getByGoodsId(@Body() params: { goodsId: string }) {
    return this.ok(await this.goodsPromoMsService.getByGoodsId(params.goodsId));
  }

  @Post('/getAllActiveDetails')
  async getAllActiveDetails() {
    return this.ok(await this.goodsPromoMsService.getAllActiveDetails());
  }

  @Post('/checkSeckillStock')
  async checkSeckillStock(@Body() params: { billNo: string; goodsId: string; quantity: number }) {
    return this.ok(await this.goodsPromoMsService.checkSeckillStock(params.billNo, params.goodsId, params.quantity));
  }
} 